/*
 *  test/test2.c
 *
 *  Harry Wei <harryxiyou@gmail.com> 2011 (C)
 */
#include <gtk/gtk.h>

gint delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
{
	gtk_main_quit();
	return FALSE;
}

GtkWidget *close_button = NULL;
GtkWidget *tooltips_button = NULL;
GtkWidget *text_button = NULL;
GtkWidget *icon_button = NULL;
GtkWidget *both_button = NULL;
GtkWidget *entry = NULL;

void radio_event(GtkWidget *widget, gpointer data)
{
	if (GTK_TOGGLE_BUTTON(text_button)->active)
		gtk_toolbar_set_style(GTK_TOOLBAR(data), GTK_TOOLBAR_TEXT);
	else if (GTK_TOGGLE_BUTTON(icon_button)->active)
		gtk_toolbar_set_style(GTK_TOOLBAR(data), GTK_TOOLBAR_ICONS);
	else if (GTK_TOGGLE_BUTTON(both_button)->active)
		gtk_toolbar_set_style(GTK_TOOLBAR(data), GTK_TOOLBAR_BOTH);
}

void toggle_event(GtkWidget *widget, gpointer data) 
{
	gtk_toolbar_set_tooltips(GTK_TOOLBAR(data), GTK_TOGGLE_BUTTON(widget)->active);
}

int main(int argc, char *argv[])
{
	GtkWidget *dialog = NULL;
	GtkWidget *iconw = NULL;
	GtkWidget *handlebox = NULL;
	GtkWidget *toolbar = NULL;

	//
	gtk_init(&argc, &argv);
	dialog = gtk_dialog_new();
	gtk_window_set_title(GTK_WINDOW(dialog), "Harry Wei");
	gtk_widget_set_size_request(GTK_WIDGET(dialog), 600, 300);
	GTK_WINDOW(dialog)->allow_shrink = TRUE;
	g_signal_connect(G_OBJECT(dialog), "delete_event", G_CALLBACK(delete_event), NULL);
	gtk_widget_realize(dialog);
	handlebox = gtk_handle_box_new();
	//
	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), handlebox, FALSE, FALSE, 5);
	toolbar = gtk_toolbar_new();
	gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
	gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
	gtk_container_set_border_width(GTK_TOOLBAR(toolbar), 5);
	gtk_container_add(GTK_CONTAINER(handlebox), toolbar);
	//
	iconw = gtk_image_new_from_file("1.png");
	close_button = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
						"Close",
						"Closes this app",
						"Private",
						iconw,
						GTK_SIGNAL_FUNC(delete_event),
						NULL);
	gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
	//
	iconw = gtk_image_new_from_file("1.png");
	icon_button = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
						GTK_TOOLBAR_CHILD_RADIOBUTTON,
						NULL,
						"Icon",
						"Only icons in toolbar",
						"Private",
						iconw,
						GTK_SIGNAL_FUNC(radio_event),
						toolbar);
	gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
	//
	iconw = gtk_image_new_from_file("1.png");
	text_button = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
						GTK_TOOLBAR_CHILD_RADIOBUTTON,
						icon_button,
						"Text",
						"Only texts in toolbar",
						"Private",
						iconw,
						GTK_SIGNAL_FUNC(radio_event),
						toolbar);
	gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
	//
	iconw = gtk_image_new_from_file("1.png");
	both_button = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
						GTK_TOOLBAR_CHILD_RADIOBUTTON,
						text_button,
						"Both",
						"icons and texts in toolbar",
						"Private",
						iconw,
						GTK_SIGNAL_FUNC(radio_event),
						toolbar);
	gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(both_button), TRUE);
	//
	iconw = gtk_image_new_from_file("1.png");
	tooltips_button = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
						GTK_TOOLBAR_CHILD_RADIOBUTTON,
						NULL,
						"Tooltips",
						"Toolbar with or without tips",
						"Private",
						iconw,
						GTK_SIGNAL_FUNC(toggle_event),
						toolbar);
	gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tooltips_button), TRUE);
	//
	entry = gtk_entry_new();
	gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
					entry,
					"This is just an entry",
					"Private");
	gtk_widget_show(entry);
	//
	gtk_widget_show(toolbar);
	gtk_widget_show(handlebox);
	gtk_widget_show(dialog);
	gtk_main();
	return 0;
}
